﻿using Spire.Xls;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GL_CommonPrint
{
    internal class FileFormatConverter
    {
        internal bool ExcelToPDF(string excelFilePath, string pdfSavePath)
        {
            try
            {
                var workbook = new Workbook();

                //// 判断横屏PDF还是竖屏PDF
                //var heightNum = workbook.Worksheets[0].Rows.Count();
                //var widthNum = workbook.Worksheets[0].Columns.Count();

                //if (heightNum * 2 > widthNum)
                //{
                //    //竖屏
                //}
                //else
                //{
                //    //横屏
                //}

                // 根据表格自己的横向纵向转换PDF的视图
                workbook.ConverterSetting.PrintWithSheetPageSetting = true;

                workbook.LoadFromFile(excelFilePath);
                workbook.SaveToFile(pdfSavePath);

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }



        }
    }
}
